
package com.be.beadmin.service.repository;

import com.be.beadmin.service.entity.FactoryCalendar;
import com.be.beadmin.service.entity.FactoryCalendarItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
* @author chenwei
* @date 2023-02-22
**/
public interface FactoryCalendarItemRepository extends JpaRepository<FactoryCalendarItem, String>, JpaSpecificationExecutor<FactoryCalendarItem> {

    FactoryCalendarItem findFactoryCalendarItemByIdAndDelete(String id, Integer delete);

    FactoryCalendarItem findFactoryCalendarItemById(String id);

    FactoryCalendarItem findFactoryCalendarItemByDateAndFactoryCalendarAndDelete(Date date, FactoryCalendar factoryCalendar, int delete);
    @Query(value = "select fci.day_off from t_factory_calendar_item fci where fci.date = ?1 and fci.t_factory_calendar_item = ?2 and fci.is_delete = ?3;",nativeQuery = true)
    boolean findDayOffByDateAndFactoryCalendarAndDelete(Date date, String factoryCalendarId, int delete);

    @Query(value = "select count(fci.*) from t_factory_calendar_item fci where fci.date BETWEEN ?1 AND ?2 and fci.t_factory_calendar_item = ?3 and fci.day_off = ?4 and fci.is_delete = ?5;",nativeQuery = true)
    int countDayOffByDateAndFactoryCalendarAndDelete(Date startDate,Date endDate, String factoryCalendarId, boolean isDayOff, int delete);

    List<FactoryCalendarItem> findFactoryCalendarItemsByDateBetweenAndAndFactoryCalendarAndDelete(Date startDate, Date endDate, FactoryCalendar factoryCalendar, int delete);

}